package algorithm.niuke;

public class 最小重复子数组 {
    public int findLength(int[] A, int[] B) {
        int lena = A.length;
        int lenb = B.length;
        int[][] dp = new int[1002][1002];
        int max = 0;
        for (int i = 1; i <= lena; i++) {
            for (int j = 1; j <= lenb; j++) {
                int eq = A[i - 1] == B[j - 1] ? 1 : 0;
                dp[i][j] = eq * (dp[i - 1][j - 1] + eq);
                max = Math.max(dp[i][j], max);
            }
        }
        return max;
    }

    public static void main(String[] args) {
        int[] a = { 1, 0, 1, 0, 0, 0, 0, 0, 1, 1 };
        int[] b = { 1, 1, 0, 1, 1, 0, 0, 0, 0, 0 };
        最小重复子数组 run = new 最小重复子数组();
        System.out.println(run.findLength(a, b));
    }
}
